﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcShop.Models.ViewDataModels
{
    public class PollViewData
    {
        #region ==== Property =====
        public int PageIndex { get; set; }
        public int Count { get; set; }
        public int Total { get; set; }
        public string KeyWord { get; set; }

        public IEnumerable<ViewPollOptions> ViewPollOptions { get; set; }
        #endregion

        #region ==== Methods ====
        public PollViewData WithPageIndex(int pageIndex)
        {
            this.PageIndex = pageIndex;
            return this;
        }

        public PollViewData WithCount(int count)
        {
            this.Count = count;
            return this;
        }

        public PollViewData WithTotal(int pageSize)
        {
            this.Total = Math.Max((this.Count + pageSize - 1) / pageSize, 1); ;
            return this;
        }

        public PollViewData WithKeyWord(string keyWord)
        {
            this.KeyWord = keyWord;
            return this;
        }

        public PollViewData WithViewPollOptions(IEnumerable<ViewPollOptions> viewPollOptions)
        {
            this.ViewPollOptions = viewPollOptions;
            return this;
        }
        #endregion
    }

    public static class PollView
    {
        public static PollViewData Data { get { return new PollViewData(); } }
    }

    public class ViewPollOptions
    {
        public int PollOptionId { get; set; }
        public string Subject { get; set; }
        public string Options { get; set; }
        public string Color { get; set; }
        public int? Ballots { get; set; }
    }
}
